<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 管理员面板</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
            min-height: 100vh;
            display: flex;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
        }

        .sidebar-header .logo {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .sidebar-header .logo-icon {
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 18px;
            color: var(--light-color);
        }

        .sidebar-header h3 {
            font-size: 1.2rem;
            font-weight: 500;
            margin: 0;
        }

        .sidebar-header p {
            font-size: 0.8rem;
            opacity: 0.8;
            margin: 0;
        }

        .nav-menu {
            list-style: none;
            padding: 0 15px;
        }

        .nav-item {
            margin-bottom: 5px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            border-radius: 8px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .nav-link i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 16px;
        }

        .nav-link .badge {
            margin-left: auto;
            background-color: var(--light-color);
            color: var(--dark-color);
            font-size: 0.7rem;
            padding: 3px 6px;
        }

        .user-profile {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            padding: 0 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
        }

        .user-info:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 14px;
        }

        .user-name {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.7rem;
            opacity: 0.8;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .btn i {
            margin-right: 6px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
        }

        .btn-outline:hover {
            background-color: #f5f5f5;
        }

        /* 统计卡片样式 */
        .stats-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .stat-card {
            background-color: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: var(--shadow);
            transition: var(--transition);
            position: relative;
            overflow: hidden;
        }

        .stat-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }

        .stat-card::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
        }

        .stat-card.user-card::after {
            background: linear-gradient(to right, #05668d, #028090);
        }

        .stat-card.pile-card::after {
            background: linear-gradient(to right, #00a896, #02c39a);
        }

        .stat-card.charging-card::after {
            background: linear-gradient(to right, #028090, #00a896);
        }

        .stat-card.fault-card::after {
            background: linear-gradient(to right, #f44336, #ff9800);
        }

        .stat-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .stat-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
        }

        .user-card .stat-icon {
            background: linear-gradient(135deg, #05668d, #028090);
        }

        .pile-card .stat-icon {
            background: linear-gradient(135deg, #00a896, #02c39a);
        }

        .charging-card .stat-icon {
            background: linear-gradient(135deg, #028090, #00a896);
        }

        .fault-card .stat-icon {
            background: linear-gradient(135deg, #f44336, #ff9800);
        }

        .stat-title {
            font-size: 0.9rem;
            color: #777;
            font-weight: 500;
        }

        .stat-value {
            font-size: 1.8rem;
            font-weight: 600;
            margin: 10px 0;
            color: var(--dark-color);
        }

        .stat-change {
            font-size: 0.8rem;
            display: flex;
            align-items: center;
        }

        .stat-change.positive {
            color: #4caf50;
        }

        .stat-change.negative {
            color: #f44336;
        }

        /* 图表和表格区域 */
        .content-row {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 20px;
            margin-bottom: 20px;
        }

        @media (max-width: 1200px) {
            .content-row {
                grid-template-columns: 1fr;
            }
        }

        .card {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 20px;
            margin-bottom: 20px;
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .card-header h3 {
            font-size: 1.2rem;
            font-weight: 600;
            margin: 0;
            color: var(--dark-color);
        }

        .chart-container {
            height: 300px;
            position: relative;
        }

        .table-responsive {
            overflow-x: auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }

        th {
            font-weight: 500;
            color: #555;
            font-size: 0.9rem;
        }

        tr:hover {
            background-color: #f9f9f9;
        }

        .badge {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 0.75rem;
            font-weight: 500;
        }

        .badge-success {
            background-color: #e8f5e9;
            color: #4caf50;
        }

        .badge-warning {
            background-color: #fff8e1;
            color: #ff9800;
        }

        .badge-danger {
            background-color: #ffebee;
            color: #f44336;
        }

        .badge-info {
            background-color: #e3f2fd;
            color: #2196f3;
        }

        .activity-item {
            display: flex;
            align-items: center;
            padding: 10px 0;
            border-bottom: 1px solid #f5f5f5;
        }

        .activity-item:last-child {
            border-bottom: none;
        }

        .activity-icon {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            color: var(--primary-color);
            font-size: 14px;
        }

        .activity-content {
            flex: 1;
        }

        .activity-title {
            font-weight: 500;
            margin-bottom: 3px;
        }

        .activity-time {
            font-size: 0.8rem;
            color: #999;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
                overflow: hidden;
            }

            .sidebar-header h3,
            .sidebar-header p,
            .nav-link span,
            .user-name,
            .user-role {
                display: none;
            }

            .sidebar-header {
                padding: 15px 10px;
            }

            .nav-link {
                justify-content: center;
                padding: 12px 0;
            }

            .nav-link i {
                margin-right: 0;
                font-size: 18px;
            }

            .main-content {
                margin-left: 70px;
            }
        }

        @media (max-width: 768px) {
            .stats-container {
                grid-template-columns: 1fr 1fr;
            }

            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }

        @media (max-width: 576px) {
            .stats-container {
                grid-template-columns: 1fr;
            }

            .main-content {
                padding: 20px 15px;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div>
                <h3>绿能充</h3>
                <p>管理员面板</p>
            </div>
        </div>
    </div>

    <ul class="nav-menu">
        <li class="nav-item">
            <a href="/admin/dashboard" class="nav-link active">
                <i class="fas fa-tachometer-alt"></i>
                <span>仪表盘</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/user/list" class="nav-link">
                <i class="fas fa-users"></i>
                <span>用户管理</span>
                <span class="badge">5</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/pile/list" class="nav-link">
                <i class="fas fa-charging-station"></i>
                <span>充电桩管理</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/report/list" class="nav-link">
                <i class="fas fa-list-alt"></i>
                <span>充电记录</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/fault/list" class="nav-link">
                <i class="fas fa-exclamation-triangle"></i>
                <span>故障报告</span>
                <span class="badge">3</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/settings" class="nav-link">
                <i class="fas fa-cog"></i>
                <span>系统设置</span>
            </a>
        </li>
    </ul>

    <div class="user-profile">
        <div class="user-info">
            <div class="user-avatar">
                <i class="fas fa-user"></i>
            </div>
            <div>
                <div class="user-name">管理员</div>
                <div class="user-role">超级管理员</div>
            </div>
        </div>
    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <div class="header">
        <div class="page-title">
            <h1>系统概览</h1>
            <p>欢迎回来，以下是系统最新数据</p>
        </div>
        <div class="header-actions">
            <button class="btn btn-outline">
                <i class="fas fa-calendar-alt"></i> 今日
            </button>
            <button class="btn btn-outline">
                <i class="fas fa-download"></i> 导出
            </button>
        </div>
    </div>

    <!-- 统计卡片 -->
    <div class="stats-container">
        <div class="stat-card user-card">
            <div class="stat-header">
                <div class="stat-title">用户总数</div>
                <div class="stat-icon">
                    <i class="fas fa-users"></i>
                </div>
            </div>
            <div class="stat-value" th:text="${userCount}">1,248</div>
            <div class="stat-change positive">
                <i class="fas fa-arrow-up"></i> 5.2% 较上周
            </div>
        </div>

        <div class="stat-card pile-card">
            <div class="stat-header">
                <div class="stat-title">充电桩总数</div>
                <div class="stat-icon">
                    <i class="fas fa-charging-station"></i>
                </div>
            </div>
            <div class="stat-value" th:text="${pileCount}">86</div>
            <div class="stat-change positive">
                <i class="fas fa-arrow-up"></i> 2.4% 较上周
            </div>
        </div>

        <div class="stat-card charging-card">
            <div class="stat-header">
                <div class="stat-title">今日充电量</div>
                <div class="stat-icon">
                    <i class="fas fa-bolt"></i>
                </div>
            </div>
            <div class="stat-value" th:text="${todayChargingKWh} + ' kWh'">1,245 kWh</div>
            <div class="stat-change negative">
                <i class="fas fa-arrow-down"></i> 3.1% 较昨日
            </div>
        </div>

        <div class="stat-card fault-card">
            <div class="stat-header">
                <div class="stat-title">待处理故障</div>
                <div class="stat-icon">
                    <i class="fas fa-exclamation-triangle"></i>
                </div>
            </div>
            <div class="stat-value" th:text="${pendingFaults}">3</div>
            <div class="stat-change positive">
                <i class="fas fa-arrow-down"></i> 40% 较昨日
            </div>
        </div>
    </div>

    <!-- 主要内容区 -->
    <div class="content-row">
        <!-- 充电趋势图表 -->
        <div class="card">
            <div class="card-header">
                <h3>充电趋势</h3>
                <div>
                    <button class="btn btn-outline btn-sm">日</button>
                    <button class="btn btn-outline btn-sm">周</button>
                    <button class="btn btn-outline btn-sm active">月</button>
                </div>
            </div>
            <div class="chart-container">
                <!-- 这里将使用Chart.js或其他图表库 -->
                <canvas id="chargingChart"></canvas>
            </div>
        </div>

        <!-- 最近活动 -->
        <div class="card">
            <div class="card-header">
                <h3>最近活动</h3>
                <a href="#" class="btn btn-outline btn-sm">查看全部</a>
            </div>
            <div class="activity-list">
                <div class="activity-item">
                    <div class="activity-icon">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <div class="activity-content">
                        <div class="activity-title">充电桩 #A203 开始充电</div>
                        <div class="activity-time">10分钟前</div>
                    </div>
                </div>
                <div class="activity-item">
                    <div class="activity-icon">
                        <i class="fas fa-user"></i>
                    </div>
                    <div class="activity-content">
                        <div class="activity-title">新用户注册: user123</div>
                        <div class="activity-time">25分钟前</div>
                    </div>
                </div>
                <div class="activity-item">
                    <div class="activity-icon">
                        <i class="fas fa-exclamation-triangle"></i>
                    </div>
                    <div class="activity-content">
                        <div class="activity-title">充电桩 #B107 报告故障</div>
                        <div class="activity-time">1小时前</div>
                    </div>
                </div>
                <div class="activity-item">
                    <div class="activity-icon">
                        <i class="fas fa-charging-station"></i>
                    </div>
                    <div class="activity-content">
                        <div class="activity-title">充电桩 #A205 维护完成</div>
                        <div class="activity-time">2小时前</div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 最近记录表格 -->
    <div class="content-row">
        <!-- 最近充电记录 -->
        <div class="card">
            <div class="card-header">
                <h3>最近充电记录</h3>
                <a href="/admin/records" class="btn btn-outline btn-sm">查看全部</a>
            </div>
            <div class="table-responsive">
                <table>
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>用户</th>
                        <th>充电桩</th>
                        <th>开始时间</th>
                        <th>时长</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="record : ${recentRecords}">
                        <td th:text="${record.id}">1001</td>
                        <td th:text="${record.user.username}">user123</td>
                        <td th:text="${record.pile.pileCode}">A203</td>
                        <td><fmt:formatDate value="${record.startTime}" pattern="MM-dd HH:mm" /></td>
                        <td><fmt:formatDate value="${fault.reportTime}" pattern="MM-dd HH:mm" /></td>
                        <td th:text="${record.duration} + '分钟'">45分钟</td>
                        <td>
                            <span th:if="${record.status == 'charging'}" class="badge badge-warning">充电中</span>
                            <span th:if="${record.status == 'completed'}" class="badge badge-success">已完成</span>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 最近故障报告 -->
        <div class="card">
            <div class="card-header">
                <h3>最近故障报告</h3>
                <a href="/admin/faults" class="btn btn-outline btn-sm">查看全部</a>
            </div>
            <div class="table-responsive">
                <table>
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>充电桩</th>
                        <th>报告人</th>
                        <th>报告时间</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${recentRecords}" var="record">
                        <tr>
                            <td>${record.id}</td>
                            <td>${record.user.username}</td>
                            <td>${record.pile.pileCode}</td>
                            <td><fmt:formatDate value="${record.startTime}" pattern="MM-dd HH:mm" /></td>
                            <td>${record.duration} 分钟</td>
                            <td>
                                <c:choose>
                                    <c:when test="${record.status == 'charging'}">
                                        <span class="badge badge-warning">充电中</span>
                                    </c:when>
                                    <c:when test="${record.status == 'completed'}">
                                        <span class="badge badge-success">已完成</span>
                                    </c:when>
                                </c:choose>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    // 初始化充电趋势图表
    document.addEventListener('DOMContentLoaded', function() {
        const ctx = document.getElementById('chargingChart').getContext('2d');
        const chart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ['1日', '5日', '10日', '15日', '20日', '25日', '30日'],
                datasets: [{
                    label: '充电量 (kWh)',
                    data: [1200, 1900, 1700, 2100, 2300, 2500, 2200],
                    backgroundColor: 'rgba(2, 195, 154, 0.1)',
                    borderColor: 'rgba(2, 195, 154, 1)',
                    borderWidth: 2,
                    tension: 0.3,
                    fill: true
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        display: false
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        grid: {
                            color: 'rgba(0, 0, 0, 0.05)'
                        }
                    },
                    x: {
                        grid: {
                            display: false
                        }
                    }
                }
            }
        });
    });
</script>
</body>
</html>